package com.flexycore.iphone.controllers;


import com.flexycore.iphone.model.DeleteEmails;
import com.flexycore.iphone.uikit.UIAlertView;
import com.flexycore.iphone.uikit.UIAlertViewDelegate;
import com.flexycore.iphone.uikit.UIViewController;
import com.flexycore.iphone.view.PopUp;


/**
 * 
 * @author matthieu nicolazo
 *
 */
public class DeleteAlertDelegate extends UIAlertViewDelegate {
	/**
	 * 
	 */
	private MenuController menuController;
	
	/**
	 * Constructor
	 * @param m		MenuController creating this object.
	 */
	public DeleteAlertDelegate(MenuController m){
		super();
		init();
		menuController = m;
	}
	
	/**
	 * Method called by alertView when user click on any button.
	 * @param alertView			UIAlertView calling this method.
	 * @param buttonIdex		Integer of selected button index.
	 */
	//@Override
	public void alertViewClickedButtonAtIndex(UIAlertView alertView, int buttonIndex) {
		if(buttonIndex == 0){
			// "Cancel" action = do nothing
			return;
		}
		else {
			// "Delete e-mails" action
			new Thread(new DeleteEmails(menuController.getNavigationController())).start();
			// Display a pop-up during activity
			UIViewController popUpController = new UIViewController().init();
			popUpController.setView(new PopUp("Operation in progress..."));
			menuController.getNavigationController().setNavigationBarHidden(true);
			menuController.getNavigationController().pushViewControllerAnimated(popUpController, false);
		}
	}
	
}
